import logging
import os
from datetime import datetime

from api_qiyeweixin.untils.tool import join_path

now = datetime.now()
str_time = now.strftime('%Y-%m-%d %H_%M_%S')

logger = logging.getLogger(os.path.abspath(__file__))
logger.setLevel(logging.DEBUG)

stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)

file_handler = logging.FileHandler(filename=join_path("log", f"{str_time}.log"))
file_handler.setLevel(logging.DEBUG)

formatter = logging.Formatter('%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s')

file_handler.setFormatter(formatter)
stream_handler.setFormatter(formatter)

logger.addHandler(file_handler)
logger.addHandler(stream_handler)